<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<?Php
	class Cart extends Controller{
		
			function cart(){
					parent::Controller();
					$this->load->library('session');
					$this->load->model('cartmodel');
					$this->load->database();
					
				}
			
			function add_cart(){
				if($this->session->userdata('username')==""){
					echo "<script language='JavaScript'>alert('需要登录');history.back();</script>";
					}
				else{
					/*$this->load->model('cartModel');
					$result=$this->cartModel->get_proid($this->session->userdata['username']);
					//print_r($result);
					
					//exit;
					foreach($result as $key=>$value)
					{
						//$values= $value['proid'];
						$values[]= $value['proid'];
						$nums[]=$value['nums'];
						};
					print_r($values);print_r($nums);
					//exit;
					
					$proid=$_POST['proid'];
					if(in_array($proid,$values))
					{
						$data2=array(
									 	
									 )
						}*/
						$proid=$_POST['proid'];
						$username=$this->session->userdata['username'];
						
						$cart_data=$this->cartmodel->in_cart($username,$proid);
						print_r($cart_data);
						if(@$cart_data[0]->proid){
								$nums=$_POST['nums']+$cart_data[0]->nums;
								$cart_id=$cart_data[0]->shopid;
								$data2=array(
											 'nums'=>$nums,
											 );
								$this->cartmodel->update_cart($cart_id,$data2);
								echo 'ok';
							}
					
					
					
					
					
						else{
					
					
					
							@$data=array(
										
											'proid'=>$_POST[proid],
											'username'=>$this->session->userdata[username],
											'times'=>time(),
											'product_name'=>$_POST[product_name],
											'price'=>$_POST[price],
											'nums'=>$_POST[nums],
										);
							print_r($data);
							
							
							$this->cartmodel->insert_cart('gaoji_shopcar',$data);
							}//紧接着的上面的一个else结束
						
				    }
					
				}
		}
?>
</body>
</html>